/*
---
name: MPG.Gallery

description:

license: MIT-style

authors:
- Noritaka Horio

requires:
  - Core/Core
  - Core/Type
  - Core/Element
  - Core/Element.Event
  - Core/Element.Style
  - Core/Element.Dimensions
  - Core/Class
  - Core/Class.Extra
  - MPG/MPG.GalleryController

provides: [MTGallery.Gallery]

...
*/
(function($){

	var MPG = this.MPG = (this.MPG || {});

	MPG.Gallery = new Class({

		Implements: [Options, Events],

		options: {
			imageClass: 'photography',
			actions: {
				defaultAction: '/',
				landscapeAction: '/landscape',
				portraitAction: '/portrait'
			}
		},

		_controls: [],

		initialize: function(gallery, options){
			this.setOptions(options);
			this.gallery = gallery;
			this._setup();
		},

		_setup: function(){
			var self = this;
			var options = this.options;
			var container = this.gallery;
			var controllerOptions = {
				actions: options.actions
			};
			this.controller = new MPG.GalleryController(container, controllerOptions);
		},

		addControl: function(control){
			control.setController(this.controller);
			this._controls.push(control);
			return this;
		},

		addControls: function(controls){
			var len = controls.length;
			for (var i = 0; i < len; i++){
				this.addControl(controls[i]);
			}
			return this;
		},

		run: function(){
			switch(window.orientation) {
				//landscape
				case 90:
				case -90:
					this.controller.landscapeAction();
					break;
				//portrait
				case 0:
				case 180:
					this.controller.portraitAction();
					break;
				default:
					this.controller.defaultAction();
					break;
			}
		}
	});

}(document.id));
